import request from '@/utils/request'

// 商品分类数据列表,因为级联选择器要用到里面的数据
// 参数如果不传递，则默认获取所有级别的分类
export function categoriesList() {
  return request({
    url: '/categories',
    method: 'get'
  })
}

// 参数列表
export function categoriesAttributes(data) {
  return request({
    url: `categories/${data.cat_id}/attributes`,
    method: 'get',
    params: { sel: data.attr_sel }
  })
}

// 添加动态参数或者静态属性
export function addParams(data) {
  return request({
    url: `categories/${data.cat_id}/attributes`,
    method: 'post',
    data: { attr_name: data.attr_name, attr_sel: data.attr_sel }
  })
}

// 删除参数
export function removeParams(data) {
  return request({
    url: `categories/${data.cat_id}/attributes/${data.attr_id}`,
    method: 'delete'
  })
}

// 根据 ID 查询参数
export function getCategoriesById(data) {
  return request({
    url: `categories/${data.cat_id}/attributes/${data.attr_id}`,
    method: 'get',
    params: { attr_sel: data.attr_sel }
  })
}

// 提交编辑参数
export function editCategoriesById(data) {
  return request({
    url: `categories/${data.cat_id}/attributes/${data.attr_id}`,
    method: 'put',
    data: { attr_name: data.attr_name, attr_sel: data.attr_sel }
  })
}

// 提交Tag标签编辑参数
export function attributeValue(data) {
  return request({
    url: `categories/${data.cat_id}/attributes/${data.attr_id}`,
    method: 'put',
    data: { attr_name: data.attr_name, attr_sel: data.attr_sel, attr_vals: data.attr_vals.join(' ') }
  })
}
